/// Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Windows.Forms;
using NUnit.Framework;
using NUnit.Extensions.Forms;
using Microsoft.VSPowerToys.PackInstaller;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Diagnostics;

namespace GUITestScenarios
{
    [TestFixture]
    public class ToolSelectionTests : NUnitFormTest
    {
        #region Private Data and Methods
        private PackInstallerForm packInstallForm;
        private ErrorMessages errorMessages;

        /// <summary>
        /// In order to test forms with ShowDialog under NUnitForms, you have to
        /// provide a "handler" method for the Form. Normally, this handler would
        /// contain the test logic. But, that doesn't work well for the PackInstaller
        /// because it uses threads. 
        /// 
        /// So, the test logic will be in a delegate method attched to the PackInstaller 
        /// form. Therefore, this is a skeleton handler and used for most tests.
        /// </summary>
        private void GenericFormHandler()
        {
        }
        #endregion

        [TestFixtureSetUp]
        public void Init()
        {
            Process[] visualStudioProcesses = Process.GetProcessesByName("devenv");
            TextWriter errorWriter = Console.Error;
            if (visualStudioProcesses.Length != 0)
            {
                errorWriter.WriteLine("You must close Visual Studio before running the test suite.");
                Assert.IsTrue(false);
            }

        }

        #region Click More/Less button Test
        /// <summary>
        /// Click the Plus Minus button. This covers the test plan's 
        /// Tool Selection scenarios 7 and 8
        /// </summary>
        [Test]
        public void ClickMoreLessButtonTest()
        {
            errorMessages = new ErrorMessages();
            packInstallForm = new PackInstallerForm(TestStrings.GeneralTestPackFeedXml);
            packInstallForm.OnPacksLoaded += new EventHandler<EventArgs>(MoreLesssButtonHandler);
            ExpectModal("PackInstallerForm", "GenericFormHandler");
            packInstallForm.ShowDialog();
            errorMessages.printErrors("ClickMoreLessButtonTest");
            Assert.AreEqual(0, errorMessages.Count, "ClickMoreLessButtonTest failed. Check Console output for error messages.");
        }

        /// <summary>
        /// Callback delegate for ClickPlusMinusButtonExerciser logic
        /// </summary>
        public void MoreLesssButtonHandler(object sender, EventArgs e)
        {
            LinkLabelTester linkTester = new LinkLabelTester("Tools and Utilities.toolsPanel.Managed Stack Explorer.layoutPanel.moreLessLinkLabel", "PackInstallerForm");
            ToolSummaryControlTester toolSummaryTester = new ToolSummaryControlTester("Tools and Utilities.toolsPanel.Managed Stack Explorer", "PackInstallerForm");
            // Verify that the button image is plus and the height is minimal
            int collapsedHeight = toolSummaryTester.Properties.Height;

            // Click the MoreLess button
            linkTester.Click();

            if (collapsedHeight >= toolSummaryTester.Properties.Height)
            {
                errorMessages.Add("Text box height did not increase when + icon was clicked. Collapsed height == " + collapsedHeight + " Expanded height == " + linkTester.Properties.Height);
            }
            // Click the MoreLess button again
            linkTester.Click();
            if (collapsedHeight != toolSummaryTester.Properties.Height)
            {
                errorMessages.Add("Text box height did not return to collapsed height when - icon was clicked.");
            }

            // Finally, click the Exit button.
            ButtonTester buttonTester = new ButtonTester("exitButton", "PackInstallerForm");
            buttonTester.Click();
        }
        #endregion

        #region Click the tool name header in the tool summary area
        /// <summary>
        /// This "test" covers the test plan's Tool Selection Scenario 6. The test code cannot 
        /// verify that we launched a web browser and connected to the correct web page. 
        /// That must be done manually/visually. This "test" can verify that no errors were 
        /// encountered in launching a web browser so, it's useful anyway.
        /// It's a good idea to run this particular test several times with different registered browsers
        /// </summary>
        [Test]
        public void ClickToolNameExerciser()
        {
            errorMessages = new ErrorMessages();
            packInstallForm = new PackInstallerForm(TestStrings.GeneralTestPackFeedXml);
            packInstallForm.OnPacksLoaded += new EventHandler<EventArgs>(ClickToolNameHandler);
            ExpectModal("PackInstallerForm", "GenericFormHandler");
            packInstallForm.ShowDialog();
            errorMessages.printErrors("ClickToolNameExerciser");
            Assert.AreEqual(0, errorMessages.Count, "ClickToolNameExerciser failed. Check Console output for error messages.");
        }

        public void ClickToolNameHandler(object sender, EventArgs e)
        {
            LinkLabelTester ManagedStackExplorerTester = new LinkLabelTester("Tools and Utilities.toolsPanel.Managed Stack Explorer.layoutPanel.toolNameLinkLabel", "PackInstallerForm");
            ManagedStackExplorerTester.Click();
            packInstallForm.Close();
            return;
        }
        #endregion

        #region Check one tool for installation
        /// <summary>
        /// Check the install box for only 1 tool.  
        /// Covers Test Plan's Tools Selection Scenarios 1 and 4 as well as
        /// Main GUI Functions scenarios 1 and 2
        /// Verifies the following:
        /// 1. The Install Software button is disabled before selecting anything
        /// 2. After clicking the Managed Stack Explorer's check box that
        ///     a. The state of the Tools and Utilities pack's check box is undetermined
        ///     b. The Managed Stack Explorer's check box is checked
        ///     c. No other tools are checked
        /// 3. The Install Software button is enabled after selecting one tool
        ///
        /// </summary>
        [Test]
        public void CheckOneToolTest()
        {
            errorMessages = new ErrorMessages();
            //packInstallForm = new PackInstallerForm(TestStrings.GeneralTestPackFeedXml);
            packInstallForm = new PackInstallerForm("");
            packInstallForm.OnPacksLoaded += new EventHandler<EventArgs>(CheckOneToolHandler);
            ExpectModal("PackInstallerForm", "GenericFormHandler");
            packInstallForm.ShowDialog();
            errorMessages.printErrors("CheckOneToolTest");
            Assert.AreEqual(0, errorMessages.Count, "CheckOneToolTest failed. Check Console output for error messages.");
        }

        /// <summary>
        ///  This is the delegate callback method that contains the Check One Tool test logic.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void CheckOneToolHandler(object sender, EventArgs e)
        {
            ButtonTester installSoftwareButtonTester = new ButtonTester("installSoftwareButton", "PackInstallerForm");
            PanelControlTester packListControlTester = new PanelControlTester("packListPanel", "PackInstallerForm");
            if (packListControlTester.InnerControls.Count < 2)
            {
                errorMessages.Add("No Controls in " + packListControlTester.ControlName);
            }

            // Verify that the Install button is disabled
            if (installSoftwareButtonTester.Properties.Enabled == true)
            {
                errorMessages.Add("Install software button is enabled before software was selected.");
            }

            CheckBoxTester ManagedStackExplorertoolCheckBoxTester = new CheckBoxTester("Tools and Utilities.toolsPanel.Managed Stack Explorer.layoutPanel.installToolCheckBox", "PackInstallerForm");
            ManagedStackExplorertoolCheckBoxTester.Click();

            // Verify that the Install button is now enabled
            if (installSoftwareButtonTester.Properties.Enabled != true)
            {
                errorMessages.Add("Install software button is disabled after one tool was selected.");
            }

            foreach (Control pack in packListControlTester.InnerControls)
            {
                PackListControlTester packListTester = new PackListControlTester(pack.Name, "PackInstallerForm");
                PanelControlTester toolsPanelTester = new PanelControlTester(pack.Name + ".toolsPanel", "PackInstallerForm");
                CheckBoxTester installPackCheckBoxTester = new CheckBoxTester(pack.Name + ".headerPanel.installPackCheckBox");

                // Verify that the checkbox for the Pack is not checked
                if (installPackCheckBoxTester.Properties.CheckState == CheckState.Checked)
                {
                    errorMessages.Add("Checkbox for pack '" + pack.Name + "' is checked.");
                }
                if ((pack.Name == "Tools and Utilities") &&
                    (installPackCheckBoxTester.Properties.CheckState != CheckState.Indeterminate))
                {
                    errorMessages.Add("Checkbox for pack '" + pack.Name + "' is not == CheckState.Indeterminate.");
                }
                // Verify that each tool in the pack is checked
                foreach (Control tool in toolsPanelTester.InnerControls)
                {
                    CheckBoxTester toolCheckBoxTester = new CheckBoxTester(pack.Name + ".toolsPanel." + tool.Name + ".layoutPanel.installToolCheckBox", "PackInstallerForm");
                    if (pack.Name == "Tools and Utilities" && tool.Name == "Managed Stack Explorer")
                    {
                        if (toolCheckBoxTester.Properties.CheckState != CheckState.Checked)
                        {
                            errorMessages.Add("Tool '" + tool.Name + "' in Pack '" + pack.Name + "' is not checked.");
                        }
                    }
                    else
                    {
                        if ((!tool.Name.Contains(".")) && toolCheckBoxTester.Properties.CheckState == CheckState.Checked)
                        {
                            errorMessages.Add("Tool '" + tool.Name + "' in Pack '" + pack.Name + "' is checked.");
                        }
                    }
                }
            }
            packInstallForm.Close();
            return;
        }
        #endregion

        #region Check All Packs for installation
        /// <summary>
        /// Check the install box for all packs. Covers Test Plan's 
        /// Tools Selection Scenarios 2 and 5 and the install portion of
        /// Main GUI Finctions scenario 1.
        /// Verifies the following:
        /// 1. The Install Software button is disabled before selecting packs
        /// 2. After checking a pack's check box that
        ///     a. The state of the pack's check box is checked
        ///     b. Each tool in the pack is also checked
        /// 3. The Install Software button is enabled after selecting packs
        /// </summary>
        [Test]
        public void CheckAllPacksTest()
        {
            errorMessages = new ErrorMessages();
            packInstallForm = new PackInstallerForm(TestStrings.GeneralTestPackFeedXml);
            packInstallForm.OnPacksLoaded += new EventHandler<EventArgs>(CheckAllPacksHandler);
            ExpectModal("PackInstallerForm", "GenericFormHandler");
            packInstallForm.ShowDialog();
            errorMessages.printErrors("CheckAllPacksTest");
            Assert.AreEqual(0, errorMessages.Count, "CheckAllPacksTest failed. Check Console output for error messages.");
        }

        /// <summary>
        ///  This is the delegate callback method that contains the Check All Packs test logic.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void CheckAllPacksHandler(object sender, EventArgs e)
        {
            ButtonTester installSoftwareButtonTester = new ButtonTester("installSoftwareButton", "PackInstallerForm");
            PanelControlTester packListControlTester = new PanelControlTester("packListPanel", "PackInstallerForm");
            if (packListControlTester.InnerControls.Count < 2)
            {
                errorMessages.Add("No Controls in " + packListControlTester.ControlName);
            }

            // Verify that the Install button is disabled
            if (installSoftwareButtonTester.Properties.Enabled == true)
            {
                errorMessages.Add("Install software button is enabled before packs are selected.");
            }

            foreach (Control pack in packListControlTester.InnerControls)
            {
                PackListControlTester packListTester = new PackListControlTester(pack.Name, "PackInstallerForm");
                PanelControlTester toolsPanelTester = new PanelControlTester(pack.Name + ".toolsPanel", "PackInstallerForm");
                CheckBoxTester installPackCheckBoxTester = new CheckBoxTester(pack.Name + ".headerPanel.installPackCheckBox");

                // Check each Pack for installation
                installPackCheckBoxTester.Click();
                // Verify that the checkbox for the Pack is checked
                if (installPackCheckBoxTester.Properties.CheckState != CheckState.Checked)
                {
                    errorMessages.Add("Checkbox for pack '" + pack.Name + "' is not checked.");
                }
                // Verify that each tool in the pack is checked
                foreach (Control tool in toolsPanelTester.InnerControls)
                {
                    CheckBoxTester toolCheckBoxTester = new CheckBoxTester(pack.Name + ".toolsPanel." + tool.Name + ".layoutPanel.installToolCheckBox", "PackInstallerForm");
                    if ((!tool.Name.Contains(".")) && toolCheckBoxTester.Properties.CheckState != CheckState.Checked)
                    {
                        errorMessages.Add("Tool '" + tool.Name + "' in Pack '" + pack.Name + "' is not checked.");
                    }
                }
            }
            // Verify that the Install button is now enabled
            if (installSoftwareButtonTester.Properties.Enabled != true)
            {
                errorMessages.Add("Install software button is disabled after packs are selected.");
            }
            packInstallForm.Close();
            return;
        }
        #endregion

        #region Unselect a pack Test
        /// <summary>
        /// This test unselects a selected pack. 
        /// Covers Test Plan's Tools Selection Scenario 3
        /// </summary>
        [Test]
        public void UnselectOnePackTest()
        {
            errorMessages = new ErrorMessages();
            packInstallForm = new PackInstallerForm(TestStrings.GeneralTestPackFeedXml);
            packInstallForm.OnPacksLoaded += new EventHandler<EventArgs>(UnselectOnePackHandler);
            ExpectModal("PackInstallerForm", "GenericFormHandler");
            packInstallForm.ShowDialog();
            errorMessages.printErrors("UnselectPackTest");
            Assert.AreEqual(0, errorMessages.Count, "UnselectPackTest failed. Check Console output for error messages.");
        }
        public void UnselectOnePackHandler(object sender, EventArgs e)
        {
            PanelControlTester packListControlTester = new PanelControlTester("packListPanel", "PackInstallerForm");

            #region First, Click the checkboxes for all Packs
            foreach (Control pack in packListControlTester.InnerControls)
            {
                PackListControlTester packListTester = new PackListControlTester(pack.Name, "PackInstallerForm");
                PanelControlTester toolsPanelTester = new PanelControlTester(pack.Name + ".toolsPanel", "PackInstallerForm");
                CheckBoxTester installPackCheckBoxTester = new CheckBoxTester(pack.Name + ".headerPanel.installPackCheckBox");

                // Check each Pack for installation
                installPackCheckBoxTester.Click();
                // Verify that the checkbox for the Pack is checked
                if (installPackCheckBoxTester.Properties.CheckState != CheckState.Checked)
                {
                    errorMessages.Add("Checkbox for pack '" + pack.Name + "' is not checked.");
                }
                // Verify that each tool in the pack is checked
                foreach (Control tool in toolsPanelTester.InnerControls)
                {
                    CheckBoxTester toolCheckBoxTester = new CheckBoxTester(pack.Name + ".toolsPanel." + tool.Name + ".layoutPanel.installToolCheckBox", "PackInstallerForm");
                    if ((!tool.Name.Contains(".")) && toolCheckBoxTester.Properties.CheckState != CheckState.Checked)
                    {
                        errorMessages.Add("Tool '" + tool.Name + "' in Pack '" + pack.Name + "' is not checked.");
                    }
                }
            }
            #endregion

            #region Click the checkbox for one pack and verify that its tools are not selected
            CheckBoxTester uncheckPackCheckBoxTester = new CheckBoxTester("Tools and Utilities.headerPanel.installPackCheckBox");
            uncheckPackCheckBoxTester.Click();
            // Verify that the pack's install check box is unchecked
            if (uncheckPackCheckBoxTester.Properties.CheckState != CheckState.Unchecked)
            {
                errorMessages.Add("After unselecting Tools and Utilities.headerPanel.installPackCheckBox, its state is " + uncheckPackCheckBoxTester.Properties.CheckState);
            }

            // Verify that each tool in the pack is unchecked
            PanelControlTester toolPanelTester = new PanelControlTester("Tools and Utilities.toolsPanel", "PackInstallerForm");
            foreach (Control tool in toolPanelTester.InnerControls)
            {
                CheckBoxTester toolCheckBoxTester = new CheckBoxTester("Tools and Utilities.toolsPanel." + tool.Name + ".layoutPanel.installToolCheckBox", "PackInstallerForm");
                if ((!tool.Name.Contains(".")) && toolCheckBoxTester.Properties.CheckState != CheckState.Unchecked)
                {
                    errorMessages.Add("Tool '" + tool.Name + "' in Pack 'Tools and Utilities' is not unchecked. State ==" + toolCheckBoxTester.Properties.CheckState);
                }
            }

            // Verify that the other packs were not affected
            foreach (Control pack in packListControlTester.InnerControls)
            {
                PackListControlTester packListTester = new PackListControlTester(pack.Name, "PackInstallerForm");
                PanelControlTester toolsPanelTester = new PanelControlTester(pack.Name + ".toolsPanel", "PackInstallerForm");
                CheckBoxTester installPackCheckBoxTester = new CheckBoxTester(pack.Name + ".headerPanel.installPackCheckBox");

                if (pack.Name != "Tools and Utilities")
                {
                    // Verify that the checkbox for the Pack is checked
                    if (installPackCheckBoxTester.Properties.CheckState != CheckState.Checked)
                    {
                        errorMessages.Add("Checkbox for pack '" + pack.Name + "' is not checked.");
                    }
                    // Verify that each tool in the pack is checked
                    foreach (Control tool in toolsPanelTester.InnerControls)
                    {
                        CheckBoxTester toolCheckBoxTester = new CheckBoxTester(pack.Name + ".toolsPanel." + tool.Name + ".layoutPanel.installToolCheckBox", "PackInstallerForm");
                        if ((!tool.Name.Contains(".")) && toolCheckBoxTester.Properties.CheckState != CheckState.Checked)
                        {
                            errorMessages.Add("Tool '" + tool.Name + "' in Pack '" + pack.Name + "' is not checked.");
                        }
                    }
                }
            }
            #endregion

            packInstallForm.Close();
            return;
        }

        #endregion

        #region Unselect one tool
        /// <summary>
        /// This test unselects one tool after selecting all packs
        /// It verifies that:
        /// 1. only the one tool is unchecked
        /// 2. The tool's pack's checkbox becomes indetermintate rathe than checked
        /// 3. Other packs are still selected and checked.
        /// </summary>
        [Test]
        public void UnselectOneToolTest()
        {
            errorMessages = new ErrorMessages();
            packInstallForm = new PackInstallerForm(TestStrings.GeneralTestPackFeedXml);
            packInstallForm.OnPacksLoaded += new EventHandler<EventArgs>(UnselectOneToolHandler);
            ExpectModal("PackInstallerForm", "GenericFormHandler");
            packInstallForm.ShowDialog();
            errorMessages.printErrors("UnselectOneToolTest");
            Assert.AreEqual(0, errorMessages.Count, "UnselectOneToolTest failed. Check Console output for error messages.");
        }
        public void UnselectOneToolHandler(object sender, EventArgs e)
        {
            PanelControlTester packListControlTester = new PanelControlTester("packListPanel", "PackInstallerForm");

            #region First, Click the checkboxes for all Packs
            foreach (Control pack in packListControlTester.InnerControls)
            {
                PackListControlTester packListTester = new PackListControlTester(pack.Name, "PackInstallerForm");
                PanelControlTester toolsPanelTester = new PanelControlTester(pack.Name + ".toolsPanel", "PackInstallerForm");
                CheckBoxTester installPackCheckBoxTester = new CheckBoxTester(pack.Name + ".headerPanel.installPackCheckBox");

                // Check each Pack for installation
                installPackCheckBoxTester.Click();
                // Verify that the checkbox for the Pack is checked
                if (installPackCheckBoxTester.Properties.CheckState != CheckState.Checked)
                {
                    errorMessages.Add("Checkbox for pack '" + pack.Name + "' is not checked.");
                }
                // Verify that each tool in the pack is checked
                foreach (Control tool in toolsPanelTester.InnerControls)
                {
                    CheckBoxTester toolCheckBoxTester = new CheckBoxTester(pack.Name + ".toolsPanel." + tool.Name + ".layoutPanel.installToolCheckBox", "PackInstallerForm");
                    if ((!tool.Name.Contains(".")) && toolCheckBoxTester.Properties.CheckState != CheckState.Checked)
                    {
                        errorMessages.Add("Tool '" + tool.Name + "' in Pack '" + pack.Name + "' is not checked.");
                    }
                }
            }
            #endregion

            CheckBoxTester ManagedStackExplorertoolCheckBoxTester = new CheckBoxTester("Tools and Utilities.toolsPanel.Managed Stack Explorer.layoutPanel.installToolCheckBox", "PackInstallerForm");
            ManagedStackExplorertoolCheckBoxTester.Click();

            foreach (Control pack in packListControlTester.InnerControls)
            {
                PackListControlTester packListTester = new PackListControlTester(pack.Name, "PackInstallerForm");
                PanelControlTester toolsPanelTester = new PanelControlTester(pack.Name + ".toolsPanel", "PackInstallerForm");
                CheckBoxTester installPackCheckBoxTester = new CheckBoxTester(pack.Name + ".headerPanel.installPackCheckBox");

                // Verify that the checkbox for the Tools and Utilities Pack is not checked
                if (pack.Name == "Tools and Utilities")
                {
                    if (installPackCheckBoxTester.Properties.CheckState != CheckState.Indeterminate)
                    {
                        errorMessages.Add("Checkbox for pack '" + pack.Name + "' is not == CheckState.Indeterminate. State == " + installPackCheckBoxTester.Properties.CheckState);
                    }
                }
                // Verify that other packs are still checked
                else if (installPackCheckBoxTester.Properties.CheckState != CheckState.Checked)
                {
                    errorMessages.Add("Checkbox for pack '" + pack.Name + "' is not checked. State == " + installPackCheckBoxTester.Properties.CheckState);
                }

                // Verify that all tools except Managed Stack Explorer are checked
                foreach (Control tool in toolsPanelTester.InnerControls)
                {
                    CheckBoxTester toolCheckBoxTester = new CheckBoxTester(pack.Name + ".toolsPanel." + tool.Name + ".layoutPanel.installToolCheckBox", "PackInstallerForm");
                    if (pack.Name == "Tools and Utilities" && tool.Name == "Managed Stack Explorer")
                    {
                        if (toolCheckBoxTester.Properties.CheckState != CheckState.Unchecked)
                        {
                            errorMessages.Add("Tool '" + tool.Name + "' in Pack '" + pack.Name + "' is not checked.");
                        }
                    }
                    else
                    {
                        if ((!tool.Name.Contains(".")) && toolCheckBoxTester.Properties.CheckState != CheckState.Checked)
                        {
                            errorMessages.Add("Tool '" + tool.Name + "' in Pack '" + pack.Name + "' is not checked.");
                        }
                    }
                }
            }
            packInstallForm.Close();
            return;
        }

        #endregion

        #region Check All Packs and switch to mainenance mode
        /// <summary>
        /// Checks all packs and then switches to maintenance mode.
        /// The mode switch should clear all checkboxes. The test covers the test plan's
        /// Main GUI Functions scenario 1 (unistall mode)
        /// </summary>
        [Test]
        public void CheckAllAndSwitchModeTest()
        {
            errorMessages = new ErrorMessages();
            packInstallForm = new PackInstallerForm(TestStrings.GeneralTestPackFeedXml);
            packInstallForm.OnPacksLoaded += new EventHandler<EventArgs>(CheckAndSwitchHandler);
            ExpectModal("PackInstallerForm", "GenericFormHandler");
            packInstallForm.ShowDialog();
            errorMessages.printErrors("CheckAllAndSwitchModeTest");
            Assert.AreEqual(0, errorMessages.Count, "CheckAllAndSwitchModeTest failed. Check Console output for error messages.");
        }

        /// <summary>
        ///  This is the delegate callback method that contains the test logic.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void CheckAndSwitchHandler(object sender, EventArgs e)
        {
            ButtonTester installSoftwareButtonTester = new ButtonTester("installSoftwareButton", "PackInstallerForm");
            PanelControlTester packListControlTester = new PanelControlTester("packListPanel", "PackInstallerForm");

            // Verify that, since we are in install Mode, the button says Install
            if (installSoftwareButtonTester.Text != "&Install...")
            {
                errorMessages.Add("Install software button text is " + installSoftwareButtonTester.Text + " in install mode.");
            }

            // Verify that the Install button is disabled
            if (installSoftwareButtonTester.Properties.Enabled == true)
            {
                errorMessages.Add("Install software button is enabled before packs are selected.");
            }

            foreach (Control pack in packListControlTester.InnerControls)
            {
                PackListControlTester packListTester = new PackListControlTester(pack.Name, "PackInstallerForm");
                PanelControlTester toolsPanelTester = new PanelControlTester(pack.Name + ".toolsPanel", "PackInstallerForm");
                CheckBoxTester installPackCheckBoxTester = new CheckBoxTester(pack.Name + ".headerPanel.installPackCheckBox");

                // Check each Pack for installation
                installPackCheckBoxTester.Click();
                // Verify that the checkbox for the Pack is checked
                if (installPackCheckBoxTester.Properties.CheckState != CheckState.Checked)
                {
                    errorMessages.Add("Checkbox for pack '" + pack.Name + "' is not checked.");
                }
                // Verify that each tool in the pack is checked
                foreach (Control tool in toolsPanelTester.InnerControls)
                {
                    CheckBoxTester toolCheckBoxTester = new CheckBoxTester(pack.Name + ".toolsPanel." + tool.Name + ".layoutPanel.installToolCheckBox", "PackInstallerForm");
                    if ((!tool.Name.Contains(".")) && (toolCheckBoxTester.Properties.CheckState != CheckState.Checked))
                    {
                        errorMessages.Add("Tool '" + tool.Name + "' in Pack '" + pack.Name + "' is not checked.");
                    }
                }
            }
            // Verify that the Install button is now enabled
            if (installSoftwareButtonTester.Properties.Enabled != true)
            {
                errorMessages.Add("Install software button is disabled after packs are selected.");
            }

            // Click the maintenanceRadio button
            RadioButtonTester radioTester = new RadioButtonTester("headerPanel.maintenanceRadio", "PackInstallerForm");
            radioTester.Click();

            // Verify that the install buton is now disabled and says "Removal"
            if (installSoftwareButtonTester.Properties.Enabled == true)
            {
                errorMessages.Add("Install software button is still enabled after switching to maintenance mode.");
            }
            if (installSoftwareButtonTester.Text != "&Remove...")
            {
                errorMessages.Add("Install software button text is " + installSoftwareButtonTester.Text + " in maintenance mode.");
            }
            foreach (Control pack in packListControlTester.InnerControls)
            {
                PackListControlTester packListTester = new PackListControlTester(pack.Name, "PackInstallerForm");
                PanelControlTester toolsPanelTester = new PanelControlTester(pack.Name + ".toolsPanel", "PackInstallerForm");
                CheckBoxTester installPackCheckBoxTester = new CheckBoxTester(pack.Name + ".headerPanel.installPackCheckBox");

                // Verify that the checkbox for the Pack is not checked
                if (installPackCheckBoxTester.Properties.CheckState == CheckState.Checked)
                {
                    errorMessages.Add("Checkbox for pack '" + pack.Name + "' is still checked.");
                }
                // Verify that each tool in the pack is not checked
                foreach (Control tool in toolsPanelTester.InnerControls)
                {
                    CheckBoxTester toolCheckBoxTester = new CheckBoxTester(pack.Name + ".toolsPanel." + tool.Name + ".layoutPanel.installToolCheckBox", "PackInstallerForm");
                    if ((!tool.Name.Contains(".")) && toolCheckBoxTester.Properties.CheckState == CheckState.Checked)
                    {
                        errorMessages.Add("Tool '" + tool.Name + "' in Pack '" + pack.Name + "' is still checked.");
                    }
                }
            }
            packInstallForm.Close();
            return;
        }
        #endregion

    }
}
